<?php head(array('title'=>__('Browse Items'),'bodyid'=>'items','bodyclass' => 'browse')); ?>

<div id="secondary">
	<?php echo secondary_poincare();?>
</div>

<div id="primary">
	<h1>
	<?php
	if(preg_match("/\/items/", $_SERVER['REQUEST_URI'])) $itemsTitle = __('Browse Items');
	if(preg_match("/collection/", $_SERVER['REQUEST_URI'])){
		set_current_collection(get_collection_by_id($_GET['collection']));
		$itemsTitle = __('Browse Collections').' > '.collection('Name') ;
	}
	/*__('Browse Tags')*/
	if(preg_match("/tags/", $_SERVER['REQUEST_URI'])) $itemsTitle = 'Parcourir par mots clés > '.$_GET['tags'];
	if(isset($_GET['type'])) {
		$table = get_db()->getTable('ItemType');
		/* Function "findById" added in application/models/ItemTypeTable.php */
		$itemType = $table->findById($_GET['type']);
		/**/
		$itemsTitle = __('Browse Item Types').'  > '.$itemType->name;
	}
	echo $itemsTitle;
	?>
	</h1>

	<div class="items-result">
		<?php
		$totalResults = total_results();
		if($totalResults > 0){
			echo '<table><tr>';
			echo '<td>Résultat : <span class="items-number">'.__('%s items', total_results()).'</span></td>';
			if($totalResults > 1){
				?>
		    <td style="text-align:right;">
		    Afficher par :
		    </td><td>
		    <form action="<?php if (preg_match("/browse/", $_SERVER['REQUEST_URI'])) echo 'browse'; else echo 'items';?>">
		  	<?php
		  	if (isset($_GET['collection'])) echo '<input type="hidden" name="collection" value="'.$_GET['collection'].'"/>'."\n";
		  	if (isset($_GET['type'])) echo '<input type="hidden" name="type" value="'.$_GET['type'].'"/>'."\n";
		  	if (isset($_GET['tags'])) echo '<input type="hidden" name="tags" value="'.$_GET['tags'].'"/>'."\n";
		  	if (isset($_GET['search'])) echo '<input type="hidden" name="search" value="'.$_GET['search'].'"/>'."\n";
		  	?>
				<select name="sort_field" onChange="submit()">
				  <option value="" <?php if ($_GET['sort_field']=='') echo 'selected="selected"';?>>Date d'archivage</option>
				  <option value="<?php echo urldecode("Dublin+Core,Date");?>" <?php if ($_GET['sort_field']=='Dublin Core,Date') echo 'selected="selected"';?>>Date du document</option>
				  <option value="<?php echo urldecode("Dublin+Core,Title");?>" <?php if ($_GET['sort_field']=='Dublin Core,Title') echo 'selected="selected"';?>>Titre</option>
				</select>
				</form>
				</td>
				<td style="padding:0"><div class="pagination"><?php echo pagination_links(); ?></div></td>
			<?php
			}
			echo '</tr></table>';
		}
		// No answer
		else echo '<span class="items-number">Pas de résultats.</span> Merci de reformuler votre question.';
		?>
	</div>

	<?php while (loop_items()): ?>
	<div class="item">
		<table>
			<tr>
				<td class="item-description">
					<?php
					echo '<h4>'.link_to_item(item('Dublin Core', 'Title'), array('class'=>'permalink', 'title'=>'Détail')).'</h4>';
					if ($date=item('Dublin Core', 'Date')){
						echo $date;
					  if ($dateAbout = item('Item Type Metadata', 'Approximative date')) echo ' environ';
					  echo '; ';
					}
					?>
					<?php if ($type = item('Item Type Name')) echo $type.'; ';	?>
					<?php if ($dateAbout = item('Item Type Metadata', 'Events date')) echo 'Date(s) relatée(s) : '.str_replace(" ", " / ", $dateAbout).'; ';	?>
					<?php if ($creator = item('Dublin Core', 'Creator', array('delimiter'=>'; '))) echo $creator.'; ';	?>
					<?php if ($description = item('Dublin Core', 'Description', array('snippet'=>250))) echo $description.'; ';	?>
					<?php if ($text = item('Item Type Metadata', 'Text', array('snippet'=>250))) echo 'Texte du document : '.$text.'; ';	?>
					<?php if ($iframe = item('Item Type Metadata', 'Iframe')) echo '<div class="iframe">'.$iframe.'</div>';	?>
					<?php if (item_has_tags()): ?>
						<div class="item-tags"><strong><?php echo __('Tags'); ?> : </strong><?php echo item_tags_as_string_poincare(); ?></div>
					<?php endif; ?>
					<?php if ($collection = get_collection_for_item()) echo $collection->name.'; ';	?>
					<?php if ($rights = item('Dublin Core', 'Rights', array('delimiter'=>', '))) echo 'Droits : '.$rights.'; ';	?>
		    	<?php echo plugin_append_to_items_browse_each(); ?>
				</td>
				<td class="item-files">
					    <?php
							// Display the URL if present in Item Type Metadata
							if ($urls = item('Item Type Metadata', 'URL', array('all' => true))) {
								foreach($urls as $value){
									$site=explode('/', $value);
									echo '<span class="file-link">';
									echo '<a href="'.$value.'" target="_blank"><img title="'.$site['2'].'" alt="WEB" src="'.html_escape(WEB_ROOT).'/themes/poincare/images/web.png"/></a>';
		    	    		echo'</span>';
		    	    	}
							}?>
							<?php if(item_has_files()):
							echo display_files_for_item_poincare($options = array('imageSize' => 'thumbnail', 'icons'=>array('application/pdf'=>WEB_ROOT.'/themes/poincare/images/pdf.gif')), $wrapperAttributes = array('class'=>'item-file'));
					    ?>
							<?php endif;?>
		    </td>
			</tr>
		</table>
	</div>
	<?php endwhile; ?>

	<div class="pagination"><?php echo pagination_links(); ?></div>

	<?php echo plugin_append_to_items_browse(); ?>

</div><!-- end primary -->

<?php foot(); ?>
